package com.zhong.gang.app.ui.audit;

import android.view.View;

import com.zhong.gang.app.R;
import com.zhong.gang.app.api.Api;
import com.zhong.gang.app.api.HttpUtils;
import com.zhong.gang.app.databinding.ActivityAuditDetailBinding;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.http.BaseDataBean;


import androidx.annotation.NonNull;
import okhttp3.Call;


/**
 * @author Yan
 * @date 2020/6/10  9:26
 * @describe 填写此类描述
 * <p>
 * ====================================================
 */
public class AuditDetailAct extends ActBase<ActivityAuditDetailBinding> {
    private AuditDetailsController  mController;
    private int mOrderId=0;
    @Override
    public int LayoutRes() {
        return R.layout.activity_audit_detail;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "订单详情";
    }

    @Override
    public boolean showLoading() {
        return true;
    }

    @Override
    public void initView() {
        mOrderId=getIntent().getIntExtra("AuditId", 0);
        mController=new AuditDetailsController(this,bind);
        bind.auditPass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                auditOrder(1);
            }
        });
        bind.auditNoPass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                auditOrder(0);
            }
        });
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        HttpUtils.get(Api.ORDER_PAY_APPLY_DETAIL, this)
                 .addParams("id", String.valueOf(mOrderId))
                 .build().execute(new ActCallBack<BaseDataBean<AuditDetailBean>>() {
            @Override
            public void onResponse(BaseDataBean<AuditDetailBean> data) throws Exception {
                super.onResponse(data);
                 mController.notifyDataChanged(data.getResult());
            }
        });

    }


    private void auditOrder(int status){
        HttpUtils.post(Api.ORDER_PAY_APPLY_AUDIT, this)
                 .addParams("ids", String.valueOf(mOrderId))
                 .addParams("audits",String.valueOf(status))
                 .build().execute(new ActCallBack<BaseDataBean>() {
            @Override
            public void onResponse(BaseDataBean data) throws Exception {

            }

            @Override
            public void onError(String str) {

            }

            @Override
            public void onError(Call call, Exception e, int id) {

            }
        });
    }
}
